<template>
  <div style="padding:3%">
      <el-row>
          <el-col :span="12">
              <el-form :model="form" ref="videoForm" label-width="200px">
                <el-form-item v-for="(v,k,i) in form" :label="labels[i]" :key="v.id" :prop="k">
                    <el-select v-if="k=='schoolRunningType'" v-model="form[k]">
                        <el-option v-for="(v,i) in SchoolType" :key="i" :value="v.schoolRunningTypeValue" :label="v.schoolRunningTypeName"></el-option>
                    </el-select>
                    <el-select v-else-if="k=='netGridID'" v-model="form[k]">
                        <el-option v-for="v in netGridType" :key="v.id" :value="v.netGridID" :label="v.netGridName"></el-option>
                    </el-select>
                     <el-select v-else-if="k=='schoolNature'" v-model="form[k]">
                      <el-option v-for="(v,i) in SchoolNature" :key="i" :value="v.value" :label="v.type"></el-option>
                    </el-select>
                    <v-distpicker @selected="getValue" v-else-if="k=='schoolRegionalismCode'">
                    </v-distpicker>
                    <el-input-number :min="0" v-else-if="k=='stuNumbers'||k=='securityNumbers'||k=='schoolLongitude'||k=='schoolLatitude'" v-model="form[k]"></el-input-number>
                    <el-input v-else v-model="form[k]"></el-input>
                </el-form-item>
                <el-form-item align="center">
                    <el-button type="warning" @click="reset">重置</el-button>
                    <el-button type="primary" @click="addNewRecord">添加</el-button>
                </el-form-item>
              </el-form>
          </el-col>
      </el-row>
  </div>
</template>

<script>
import * as api from "@/api/schoolManage";
import * as api2 from "@/api/videoManage";
import VDistpicker from "v-distpicker";
export default {
  components: {
    VDistpicker
  },
  data() {
    return {
      num: 4,
      form: {
        schoolName: "", //'学校名称',
        schoolAddress: "", //'学校地址',
        schoolOrganizationCode: "", //'组织机构代码',
        schoolRegionalismCode: "", //'学校行政区划代码',
        schoolRunningType: "", //'学校办学类型',
        schoolNature: "", // 学校性质
        schoolSuperior: "", //'学校所属主管教育行政部门',
        stuNumbers: "", //'在校学生人数',
        principalCertID: "", //校长身份证号码
        principalName: "", //'校长姓名',
        principalContact: "", // '校长联系方式',
        branchSecurityName: "", // '分管安全保卫责任人姓名',
        branchSecurityContact: "", //'分管安全保卫责任人联系方式',
        securityName: "", // '安全保卫责任人姓名',
        securityContact: "", // '安全保卫责任人联系方式',
        policeName: "", // '治安责任人姓名',
        policeContact: "", // '治安责任人联系方式',
        securityNumbers: "", // '安全保卫人数',
        schoolLongitude: "", //'经度',
        schoolLatitude: "", //'纬度',
        netGridID: "" // '网格'
      },
      labels: [
        "学校名称",
        "组织机构代码",
        "学校行政区划代码",
        "学校地址",
        "学校办学类型",
        "学校性质",
        "学校所属主管教育行政部门",
        "在校学生人数",
        "校长身份证",
        "校长姓名",
        "校长联系方式",
        "分管安全保卫责任人姓名",
        "分管安全保卫责任人联系方式",
        "安全保卫责任人姓名",
        "分管安全保卫责任人联系方式",
        "治安责任人姓名",
        "治安责任人联系方式",
        "安全保卫人数",
        "经度",
        "纬度",
        "网格"
      ],
      SchoolType: [],
      netGridType: [],
      SchoolNature: [
        { value: "1", type: "公办" },
        { value: "2", type: "民办" },
        { value: "9", type: "其他" }
      ]
    };
  },
  methods: {
    getValue(e) {
      this.form.schoolRegionalismCode = e.area.code;
    },
    reset() {
      for (var key in this.form) {
        this.form[key] = "";
      }
    },
    addNewRecord() {
      api.addSchool(this.form).then(res => {
        if (res.data) {
          this.$message({
            type: "success",
            message: "添加成功!"
          });
        } else {
          this.$message({
            type: "error",
            message: res.message
          });
        }
      });
    }
  },
  mounted() {
    api2.fetchNetGrid().then(res => {
      this.netGridType = res.data;
    });
    api.getSchoolCode().then(res => {
      this.SchoolType = res.data.SchoolRunningType;
    });
  }
};
</script>

<style scoped>

</style>
